<template>
    <a-drawer :width="600" :title="title" placement="right" :visible="visible" :closable="false" :destroy-on-close="destroyOnClose" :mask-closable="maskClosable" @close="close">
        <Form ref="formRef" />
        <template #footer>
            <a-button @click="close">取消</a-button>
            <a-button type="primary" @click="handleSubmit">保存</a-button>
        </template>
    </a-drawer>
</template>
<script setup>
import { ref, nextTick } from 'vue'
import { useModal } from '@iframe/tools/mixins/ModelDrawerMixins'
import { add, update } from '/@/api/Inverter/Station'
import Form from './Form.vue'

const formRef = ref()
const title = ref('')
const { visible, destroyOnClose, maskClosable, close, submit } = useModal()
const emits = defineEmits(['close'])
const open = row => {
    visible.value = true
    if (row) {
        title.value = '修改电站'
        nextTick().then(() => {
            formRef.value.setForm(row)
        })
    } else {
        title.value = '新增电站'
    }
}
const handleSubmit = () => {
    submit({ formRef: formRef, save: add, update: update }).then(() => {
        emits('close')
        close()
    })
}
defineExpose({ open })
</script>
